var pageNum=1,pageSize=4,pageTotal=0;
var pageNum2=1,pageSize2=4,pageTotal2=0;
var pageNum3=1,pageSize3=4,pageTotal3=0;
$(function(){
	loadAllAecruiterMessage();
	
	$("#showAllrecruiterTable").show();
});

//显示所有招聘者信息
function showAllRecruiter(){
	$("#showAllrecruiterTable").show();
	$("#showRegisterRecruiterTable").hide();
	$("#showJuBaoMessageTable").hide();
	loadAllAecruiterMessage();
}

function loadAllAecruiterMessage(){
	utilAjax("/recruiter/queryAllBasicMessgae","pageNum="+pageNum+"&pageSize="+pageSize,"get",
			function(data){
		pageNum = data.pageNum;
		pageSize = data.pageSize;
		pageTotal = data.pages;
		parseAllAecruiterMessage(data.list);
	});
}

function parseAllAecruiterMessage(lists){
	var appCon = "<tr><td colspan='9' align='center'><font size='5'>所有招聘者</font></td></tr>" +
			"<tr class='info text-info'><td>编号</td><td>头像</td><td>姓名</td><td>密码</td><td>手机</td><td>身份证</td><td>邮箱</td><td>简介</td><td>状态</td></tr>";
	if(lists!=""){
		$.each(lists,function(i,a){
			appCon += "<tr>"+
						"<td>"+a.recruiter_id+"</td>"+
						"<td><img src='/image/"+a.recruiter_img+"' width='50' height='50' class='img-thumbnail'></td>"+
						"<td>"+a.recruiter_name+"</td>"+
						"<td>"+a.recruiter_ps+"</td>"+
						"<td>"+a.recruiter_phone+"</td>"+
						"<td>"+a.recruiter_card+"</td>"+
						"<td>"+a.recruiter_email+"</td>"+
						"<td><textarea class='form-control' rows='2' readonly='readonly'>"+a.recruiter_msg+"</textarea></td>"+
						"<td>"+(a.recruiter_statei==1?"<font color='red'>禁用</font>":"<font color='green'>启用</font>")+"</td>"+
					"</tr>";
		});
		appCon+= "<tr><td colspan='9' align='center'>当前页:"+pageNum+"/总页数:"+pageTotal+"</td></tr>";
		appCon+= "<tr><td colspan='9' align='center'>" +
				"<input type='button' class='btn btn-default' value='首页'  onclick=changeAecruiterPage(this)> " +
				"<input type='button' class='btn btn-default' value='上一页'  onclick=changeAecruiterPage(this)> " +
				"<input type='button' class='btn btn-default' value='下一页'  onclick=changeAecruiterPage(this)> " +
				"<input type='button' class='btn btn-default' value='末页'  onclick=changeAecruiterPage(this)> " +
			"</td></tr>";
	}else{
		appCon+= "<tr><td colspan='9' align='center'><font size='6' color='red'>暂无招聘者</font></td></tr>";
	}
	
	$("#showAllrecruiterTable").html(appCon);
}


function changeAecruiterPage(op){
	var butCon = $(op).val();
	switch(butCon){
	case "首页":
		pageNum=1;
		loadAllAecruiterMessage();
		break;
	case "上一页":
		if(pageNum>1){
			pageNum--;
			loadAllAecruiterMessage();
		}	
		break;
	case "下一页":
		if(pageNum<pageTotal){
			pageNum++;
			loadAllAecruiterMessage();
		}
		break;
	case "末页":
		pageNum=pageTotal;
		loadAllAecruiterMessage();
		break;
	}
}

//显示刚刚注册招聘者信息
function showRegisterRecruiter(){
	$("#showAllrecruiterTable").hide();
	$("#showJuBaoMessageTable").hide();
	$("#showRegisterRecruiterTable").show();
	utilAjax("/recruiter/queryBasicMessgaeByStatei","pageNum="+pageNum2+"&pageSize="+pageSize2,"get",
			function(data){
		pageNum2 = data.pageNum;
		pageSize2 = data.pageSize;
		pageTotal2 = data.pages;
		parseRegisterRecruiterMessage(data.list);
	});
}

function parseRegisterRecruiterMessage(lists){
	var appCon = "<tr><td colspan='10' align='center'><font size='5'>所有刚刚注册招聘者</font></td></tr>" +
			"<tr class='info text-info'><td>编号</td><td>头像</td><td>姓名</td><td>密码</td><td>手机</td><td>身份证</td><td>邮箱</td><td>简介</td><td>状态</td><td>操作</td></tr>";
	if(lists!=""){
		$.each(lists,function(i,a){
			appCon += "<tr>"+
						"<td>"+a.recruiter_id+"</td>"+
						"<td><img src='/image/"+a.recruiter_img+"' width='50' height='50'></td>"+
						"<td>"+a.recruiter_name+"</td>"+
						"<td>"+a.recruiter_ps+"</td>"+
						"<td>"+a.recruiter_phone+"</td>"+
						"<td>"+a.recruiter_card+"</td>"+
						"<td>"+a.recruiter_email+"</td>"+
						"<td><textarea class='form-control' rows='2' readonly='readonly'>"+a.recruiter_msg+"</textarea></td>"+
						"<td>"+(a.recruiter_statei==1?"<font color='red'>禁用</font>":"<font color='green'>启用</font>")+"</td>"+
						"<td>" +
							"<input type='button' class='btn btn-default' value='审核通过'  onclick=passApproved("+a.recruiter_id+",2)>" +
						"</td>"+
					"</tr>";
		});
		appCon+= "<tr><td colspan='10' align='center'>当前页:"+pageNum2+"/总页数:"+pageTotal2+"</td></tr>";
		appCon+= "<tr><td colspan='10' align='center'>" +
				"<input type='button' class='btn btn-default' value='首页' onclick=changeRegisterRecruiterPage(this)> " +
				"<input type='button' class='btn btn-default' value='上一页' onclick=changeRegisterRecruiterPage(this)> " +
				"<input type='button' class='btn btn-default' value='下一页' onclick=changeRegisterRecruiterPage(this)> " +
				"<input type='button' class='btn btn-default' value='末页' onclick=changeRegisterRecruiterPage(this)> " +
			"</td></tr>";
	}else{
		appCon+= "<tr><td colspan='10' align='center'><font size='6' color='red'>暂无招聘者注册</font></td></tr>";
	}
	
	$("#showRegisterRecruiterTable").html(appCon);
}

//显示举报招聘人信息
function showJuBaoMessage(){
	$("#showAllrecruiterTable").hide();
	$("#showJuBaoMessageTable").show();
	$("#showRegisterRecruiterTable").hide();
	loadJuBaoMessage();
}
function loadJuBaoMessage(){
	utilAjax("/report_recruitment_person/queryAllByRrp_report_state","pageNum="+pageNum3+"&pageSize="+pageSize3,"get",
			function(data){
		pageNum3 = data.pageNum;
		pageSize3 = data.pageSize;
		pageTotal3 = data.pages;
		parseJuBaoMessage(data.list);
	});
}

function parseJuBaoMessage(lists){
	var juBaoCon = "<tr><td colspan='9' align='center'><font size='5'>所有举报招聘者信息</font></td></tr>" +
			"<tr class='info text-info'><td>消息编号</td><td>举报内容</td><td>求职者姓名</td><td>招聘者姓名</td><td>审核状态</td><td>操作</td></tr>";
	if(lists!=""){
		$.each(lists,function(i,j){
			juBaoCon += "<tr>"+
						"<td>"+j.rrp_id+"</td>"+
						"<td><textarea class='form-control' rows='2' readonly='readonly'>"+j.rrp_context+"</textarea></td>"+
						"<td>"+j.basic_information.basic_name+"</td>"+
						"<td>"+j.recruiter_basic.recruiter_name+"</td>"+
						"<td>"+(j.rrp_report_state==3?"<font color='brown'>未审核</font>":'')+"</td>"+
						"<td>" +
							"<input type='button' class='btn btn-default' value='通过审核' onclick=judgmentOfAudit("+j.rrp_id+",2)> " +
							"<input type='button' class='btn btn-default' value='拒绝审核' onclick=judgmentOfAudit("+j.rrp_id+",1)>"+
						"</td>"+
					"</tr>";
		});
		juBaoCon+= "<tr><td colspan='7' align='center'>当前页:"+pageNum3+"/总页数:"+pageTotal3+"</td></tr>";
		juBaoCon+= "<tr><td colspan='7' align='center'>" +
				"<input type='button' class='btn btn-default' value='首页' onclick=changeJuBaoMessagePage(this)> " +
				"<input type='button' class='btn btn-default' value='上一页' onclick=changeJuBaoMessagePage(this)> " +
				"<input type='button' class='btn btn-default' value='下一页' onclick=changeJuBaoMessagePage(this)> " +
				"<input type='button' class='btn btn-default' value='末页' onclick=changeJuBaoMessagePage(this)> " +
			"</td></tr>";
	}else{
		juBaoCon+= "<tr><td colspan='7' align='center'><font size='6' color='red'>暂无举报信息</font></td></tr>";
	}
	
	$("#showJuBaoMessageTable").html(juBaoCon);
}


function changeJuBaoMessagePage(op){
	var butCon = $(op).val();
	switch(butCon){
	case "首页":
		pageNum3=1;
		loadJuBaoMessage();
		break;
	case "上一页":
		if(pageNum3>1){
			pageNum3--;
			loadJuBaoMessage();
		}	
		break;
	case "下一页":
		if(pageNum3<pageTotal3){
			pageNum3++;
			loadJuBaoMessage();
		}
		break;
	case "末页":
		pageNum3=pageTotal3;
		loadJuBaoMessage();
		break;
	}
}

//判断审核
function judgmentOfAudit(rrp_id,rrp_report_state){
	utilAjax("/report_recruitment_person/updateRrp_report_state",
			"rrp_id="+rrp_id+"&rrp_report_state="+rrp_report_state,"post",
			function(flag){
		if(flag){
			alert("审核成功");
			showAllRecruiter();
		}else{
		}
	});
}

function passApproved(recruiter_id,recruiter_statei){
	utilAjax("/recruiter/updateBasicState","recruiter_id="+recruiter_id+"&recruiter_statei="+recruiter_statei,"post",
			function(flag){
		if(flag){
			alert("修改成功");
			showAllRecruiter();
		}else{
		}
	});
}

function changeRegisterRecruiterPage(op){
	var butCon = $(op).val();
	switch(butCon){
	case "首页":
		pageNum2=1;
		showAllRecruiter();
		break;
	case "上一页":
		if(pageNum2>1){
			pageNum2--;
			showAllRecruiter();
		}	
		break;
	case "下一页":
		if(pageNum2<pageTotal2){
			pageNum2++;
			showAllRecruiter();
		}
		break;
	case "末页":
		pageNum2=pageTotal2;
		showAllRecruiter();
		break;
	}
}

function utilAjax(url,data,type,success){
	$.ajax({
		url:url,
		data:data,
		dataType:'json',
		type:type,
		success:success,
		error:function(){
		}
	});
}